// pages/login-prepare/login-prepare.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    isDrawerShow: false,
    isAgree: false,
    _isAnimation: false
  },

  goLoginCode() {
    if (this.data.isAgree) {
      wx.navigateTo({
        url: '../login-phone/login-phone',
      })
      return;
    }

    this.setData({
      isDrawerShow: true
    })

    this.startAnimation(); // 入场动画
  },

  submit() {
    this.stopAnimation();
    wx.navigateTo({
      url: '../login-phone/login-phone',
    })
  },

  startAnimation() {
    if (this.data._isAnimation) return;
    this.data._isAnimation = true;
    this.animate('.drawer-mask', [{
      opacity: 0
    }, {
      opacity: 1
    }], 200, () => {
      this.data._isAnimation = false;
    })
    this.animate('.drawer-wrap', [{
      bottom: '-424rpx'
    }, {
      bottom: 0
    }], 200, () => {
      this.data._isAnimation = false;
    })
  },
  stopAnimation() {
    if (this.data._isAnimation) return;
    this.data._isAnimation = true;

    const cb = () => {
      this.data._isAnimation = false;
      this.setData({
        isDrawerShow: false
      })
    }

    this.animate('.drawer-mask', [{
      opacity: 1
    }, {
      opacity: 0
    }], 200, cb)
    this.animate('.drawer-wrap', [{
      bottom: 0
    }, {
      bottom: '-424rpx'
    }], 200, cb)
  },

  close() {
    this.stopAnimation(); // 出场动画
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});